package org.huawei260.TiKu.ODsuanfa;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class B_2023B_4204__前缀和最大子矩阵和 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int m = sc.nextInt();

			int[][] matrix = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = sc.nextInt();
				}
			}

			System.out.println(getResult(n, m, matrix));
		}

		public static int getResult(int n, int m, int[][] matrix) {
			ArrayList<Integer> dp = new ArrayList<>();

			for (int i = 0; i < n; i++) {
				dp.add(maxSubArraySum(matrix[i])); // 一行子矩阵最大和

				for (int j = i + 1; j < n; j++) {
					dp.add(maxSubArraySum(matrixZip(Arrays.copyOfRange(matrix, i, j + 1)))); // 多行子矩阵最大和
				}
			}

			return dp.stream().max((a, b) -> a - b).orElse(0); // 求出最大和
		}

		// 最大子数组和求解
		public static int maxSubArraySum(int[] nums) {
			int[] dp = new int[nums.length];

			int res = dp[0] = nums[0];

			for (int i = 1; i < nums.length; i++) {
				dp[i] = Math.max(dp[i - 1], 0) + nums[i];
				res = Math.max(res, dp[i]);
			}

			return res;
		}

		// 多行子矩阵，压缩为一行子数组
		public static int[] matrixZip(int[][] matrix) {
			int cols = matrix[0].length;
			int rows = matrix.length;
			int[] zip = new int[cols];

			for (int c = 0; c < cols; c++) {
				for (int r = 0; r < rows; r++) {
					zip[c] += matrix[r][c];
				}
			}

			return zip;
		}
	}